package site.luojie.utils;

import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.config.BeanPostProcessor;

/**
 * @Description: 自定义Company创建过程
 * @Author jie.luo
 * @Create: 2020-05-02 21:09
 **/
public class CompanyFactoryBean implements FactoryBean<Company>, BeanPostProcessor {

    private String companyInfo;

    @Override
    public Company getObject() throws Exception {

        String[] strings = companyInfo.split(",");
        Company company = new Company();
        company.setName(strings[0]);
        company.setAddress(strings[1]);
        company.setPeoples(Integer.parseInt(strings[2]));

        return company;
    }

    @Override
    public Class<?> getObjectType() {
        return Company.class;
    }

    @Override
    public boolean isSingleton() {
        return true;
    }

    public void setCompanyInfo(String companyInfo) {
        this.companyInfo = companyInfo;
    }
}
